package mango.web.client.admin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import mango.web.client.C;
import mango.web.client.View;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Style.BorderStyle;
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.Visibility;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;

public class AdminView extends View {
	protected static AdminView adminView;

	public static AdminView get(String key) {
		if ("".equals(key)) {
			if (AdminView.adminView == null) AdminView.adminView = new AdminView().init();
			return AdminView.adminView;
		}
		return null;
	}

	public TextBox memberId;
	public TextBox contactId;
	public TextBox orchardId;
	public TextBox businessName;
	public TextBox abn;
	public HashMap<String, CheckBox> businessType = new HashMap<String, CheckBox>();
	public TextBox other;
	public HashMap<String, RadioButton> membershipType = new HashMap<String, RadioButton>();
	public HashMap<String, RadioButton> financialMember = new HashMap<String, RadioButton>();
	public HashMap<String, RadioButton> annualReport = new HashMap<String, RadioButton>();
	public ListBox authorisedContact;
	public HashMap<String, RadioButton> marketingGroupUsed = new HashMap<String, RadioButton>();
	public HashMap<String, RadioButton> packsOwnProduce = new HashMap<String, RadioButton>();
	public TextBox marketGroup;
	public TextArea brand;

	public HTML contactHTML;
	public FlexTable tableContactHeader;
	public FlexTable tableContact;
	public TextBox firstname;
	public TextBox surname;
	public TextBox BHPhone;
	public TextBox AHPhone;
	public TextBox fax;
	public TextBox identifier;
	public TextBox mobile;
	public TextBox email;
	public HashMap<String, CheckBox> service = new HashMap<String, CheckBox>();

	public TextArea businessStreet;
	public TextBox businessCity;
	public TextBox businessState;
	public TextBox businessCountry;
	public TextBox businessPostCode;
	public TextArea postalStreet;
	public TextBox postalCity;
	public TextBox postalState;
	public TextBox postalCountry;
	public TextBox postalPostCode;

	public FlexTable tableMail;
	public TextArea sampleMail;
	public FlexTable tableEmailFax;
	public TextArea sampleEmailFax;
	public FlexTable tableOrchardEmail;

	public HTML orchardHTML;
	public FlexTable tableOrchardHeader;
	public FlexTable tableOrchard;
	public TextArea physicalLocation;
	public TextBox postCode;
	public ListBox state;
	public TextBox region;

	public FlexTable tableTreeHeader;
	public FlexTable tableTree;
	public FlexTable tableVarietyHeader;
	public FlexTable tableVariety;
	public HTML varietyHtml;

	public TextBox yearPlanting;
	public ListBox varietyId;
	public TextBox DTR;
	public TextBox BTR;
	public TextBox area;
	public ListBox areaType;
	public TextBox tree;

	public HTML currentHtml;
	public TextBox currentTextBox;

	public Integer current;
	public List<String> memberIdList = new ArrayList<String>();

	//public Map<String, String> varietyMap;
	public Map<String, Integer> treeCountMap = new HashMap<String, Integer>();
	public int totalTree = 0;

	public AdminView init() {
		this.panel.setSize("1000px", "700px");

		AbsolutePanel panel;
		Label label;
		HTML html;
		TextBox textBox;
		CheckBox checkBox;
		RadioButton radioButton;
		TextArea textArea;
		Button button;
		ListBox listBox;
		int top;
		int left;

		panel = new AbsolutePanel();
		panel.setSize("1000px", "100px");
		this.panel.add(panel, 0, 0);

		// TODO:htmlMember
		html = new HTML("<b style='color:red'>16 of 1183 [1183]</b>");
		panel.add(html, 20, 0);
		this.currentHtml = html;

		left = 190;

		html = new HTML("<img src='image/first.png' style='cursor:pointer'/>");
		panel.add(html, left, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				current = 1;
				C.adminViewS.viewMember(memberIdList.get(current - 1), memberCallback);
			}
		});

		html = new HTML("<img src='image/prev.png' style='cursor:pointer'/>");
		panel.add(html, left + 40, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				current--;
				if (current < 1) current = 1;
				C.adminViewS.viewMember(memberIdList.get(current - 1), memberCallback);
			}
		});

		html = new HTML("<img src='image/next.png' style='cursor:pointer'/>");
		panel.add(html, left + 80, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				current++;
				if (current > memberIdList.size()) current = memberIdList.size();
				C.adminViewS.viewMember(memberIdList.get(current - 1), memberCallback);
			}
		});

		html = new HTML("<img src='image/last.png' style='cursor:pointer'/>");
		panel.add(html, left + 120, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				current = memberIdList.size();
				C.adminViewS.viewMember(memberIdList.get(current - 1), memberCallback);
			}
		});

		textBox = this.newTextBox("", 70);
		panel.add(textBox, left + 160, 0);
		this.currentTextBox = textBox;

		html = new HTML("<img src='image/ok.png' style='cursor:pointer'/>");
		panel.add(html, left + 240, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				try {
					int num = Integer.parseInt(currentTextBox.getText());
					if (num > 0 && num < memberIdList.size()) {
						current = num;
						C.adminViewS.viewMember(memberIdList.get(current - 1), memberCallback);
					}
				} catch (Exception ex) {

				}
			}
		});

		html = new HTML("<img src='image/search.png' style='cursor:pointer' title='Search records'/>");
		panel.add(html, left + 280, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				adminSearchView.dialogBox.show();
				adminSearchView.reset();
			}
		});

		html = new HTML("<img src='image/all.png' style='cursor:pointer' title='Load all records'/>");
		panel.add(html, left + 320, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (Window.confirm("Load all records?")) C.adminViewS.viewMemberSearch(new AdminSearchVo(), memberCallback);
			}
		});

		html = new HTML("<img src='image/add.png' style='cursor:pointer' title='Add new record'/>");
		panel.add(html, left + 360, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (Window.confirm("Add new record?")) C.adminViewS.viewMemberAdd(getMemberVo(), memberCallback);
			}
		});

		html = new HTML("<img src='image/save.png' style='cursor:pointer' title='Save this record'/>");
		panel.add(html, left + 400, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (Window.confirm("Save this record?")) C.adminViewS.viewMemberSaveMail(getMemberVo(), memberCallback);
			}
		});

		html = new HTML("<img src='image/rem.png' style='cursor:pointer' title='Remove this record'/>");
		panel.add(html, left + 440, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (Window.confirm("Remove this record?")) C.adminViewS.viewMemberRemove(C._memberVo, memberCallback);
			}
		});

		html = new HTML("<img src='image/act.png' style='cursor:pointer' title='Active new record'/>");
		panel.add(html, left + 480, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (Window.confirm("Active this record?")) C.adminViewS.viewMemberActive(C._memberVo, memberCallback);
			}
		});

		html = new HTML("<img src='image/users.png' style='cursor:pointer' title='Appended contact records'/>");
		panel.add(html, left + 520, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				adminContactView.dialogBox.show();
			}
		});

		html = new HTML("<img src='image/db.png' style='cursor:pointer' title='Database tasks'/>");
		panel.add(html, left + 560, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				adminDbView.viewShow();
			}
		});

		top = 30;
		label = this.newLabel("Members/Business Name", 150);
		panel.add(label, 34, top);

		textBox = this.newTextBox("A & N Gugich", 490);
		panel.add(textBox, 190, top);
		this.businessName = textBox;

		label = new Label("ABN");
		panel.add(label, 694, top);

		textBox = newTextBox("", 148);
		panel.add(textBox, 727, top);
		this.abn = textBox;

		top = 55;

		label = this.newLabel("Allied Business Type", 150);
		panel.add(label, 34, top);

		checkBox = new CheckBox("Grower");
		panel.add(checkBox, 190, top);
		this.businessType.put("Grower".toUpperCase(), checkBox);

		checkBox = new CheckBox("Packaging");
		panel.add(checkBox, 285, top);
		this.businessType.put("Packaging".toUpperCase(), checkBox);

		checkBox = new CheckBox("Export");
		panel.add(checkBox, 385, top);
		this.businessType.put("Export".toUpperCase(), checkBox);

		checkBox = new CheckBox("Consultant");
		panel.add(checkBox, 528, top);
		this.businessType.put("Consultant".toUpperCase(), checkBox);

		checkBox = new CheckBox("Wholesaler");
		panel.add(checkBox, 636, top);
		this.businessType.put("Wholesaler".toUpperCase(), checkBox);

		checkBox = new CheckBox("Goverment Agency");
		panel.add(checkBox, 738, top);
		this.businessType.put("Goverment Agency".toUpperCase(), checkBox);

		top = 70;

		checkBox = new CheckBox("Processor");
		panel.add(checkBox, 190, top);
		this.businessType.put("Processor".toUpperCase(), checkBox);

		checkBox = new CheckBox("Retailer");
		panel.add(checkBox, 285, top);
		this.businessType.put("Retailer".toUpperCase(), checkBox);

		checkBox = new CheckBox("Research/Extension");
		panel.add(checkBox, 385, top);
		this.businessType.put("Research/Extension".toUpperCase(), checkBox);

		checkBox = new CheckBox("Transport");
		panel.add(checkBox, 528, top);
		this.businessType.put("Transport".toUpperCase(), checkBox);

		checkBox = new CheckBox("Other");
		panel.add(checkBox, 636, top);
		this.businessType.put("Other".toUpperCase(), checkBox);

		textBox = newTextBox("", 172);
		panel.add(textBox, 695, top);
		this.other = textBox;

		label = this.newLabel("Member ID", 72);
		panel.add(label, 918, 0);

		textBox = this.newTextBox("", 74);
		panel.add(textBox, 908, 12);
		textBox.setReadOnly(true);
		this.memberId = textBox;

		label = this.newLabel("Contract ID", 74);
		panel.add(label, 918, 31);

		textBox = newTextBox("", 74);
		panel.add(textBox, 908, 43);
		textBox.setReadOnly(true);
		this.contactId = textBox;

		label = this.newLabel("Orchard ID", 74);
		panel.add(label, 918, 62);

		textBox = newTextBox("", 74);
		panel.add(textBox, 908, 74);
		textBox.setReadOnly(true);
		this.orchardId = textBox;

		// TODO:htmlMemberDetail
		AbsolutePanel panel2 = new AbsolutePanel();
		panel2.setSize("443px", "143px");

		html = new HTML("<b style='color:red'>AMIA Member Details</b>");
		panel2.add(html, 10, 0);

		this.panel.add(panel2, 10, 90);

		panel = new AbsolutePanel();
		panel.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
		panel.getElement().getStyle().setBorderWidth(2, Unit.PX);
		panel2.add(panel, 0, 13);
		panel.setSize("439px", "90px");

		top = 5;
		label = this.newLabel("Membership Type", 150);
		panel.add(label, 10, top);

		radioButton = new RadioButton("rad1", "Producer");
		panel.add(radioButton, 166, top);
		this.membershipType.put("Producer".toUpperCase(), radioButton);

		radioButton = new RadioButton("rad1", "Allied");
		panel.add(radioButton, 253, top);
		this.membershipType.put("Allied".toUpperCase(), radioButton);

		top = 25;

		label = this.newLabel("Financial Member", 150);
		panel.add(label, 10, top);

		radioButton = new RadioButton("rad2", "Yes");
		panel.add(radioButton, 166, top);
		this.financialMember.put("Yes".toUpperCase(), radioButton);

		radioButton = new RadioButton("rad2", "No");
		panel.add(radioButton, 225, top);
		this.financialMember.put("No".toUpperCase(), radioButton);

		top = 45;

		label = this.newLabel("Send annual report by", 150);
		panel.add(label, 10, top);

		radioButton = new RadioButton("rad3", "Mail");
		panel.add(radioButton, 166, top);
		this.annualReport.put("Mail".toUpperCase(), radioButton);

		radioButton = new RadioButton("rad3", "Email");
		panel.add(radioButton, 225, top);
		this.annualReport.put("Email".toUpperCase(), radioButton);

		top = 65;

		label = this.newLabel("Authorised Contract", 150);
		panel.add(label, 10, top);

		listBox = new ListBox();
		listBox.setWidth("255px");
		listBox.addItem("");
		panel.add(listBox, 166, top);
		this.authorisedContact = listBox;

		// TODO:htmlGrower
		panel2 = new AbsolutePanel();
		panel2.setSize("536px", "143px");

		html = new HTML("<b style='color:red'>Grower Packing Practices</b>");
		panel2.add(html, 10, 0);

		this.panel.add(panel2, 464, 90);

		panel = new AbsolutePanel();
		panel.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
		panel.getElement().getStyle().setBorderWidth(2, Unit.PX);
		panel2.add(panel, 0, 14);
		panel.setSize("532px", "90px");

		top = 5;

		label = this.newLabel("Marketing Group Used", 150);
		panel.add(label, 10, top);

		radioButton = new RadioButton("rad4", "Yes");
		panel.add(radioButton, 166, top);
		this.marketingGroupUsed.put("Yes".toUpperCase(), radioButton);

		radioButton = new RadioButton("rad4", "No");
		panel.add(radioButton, 213, top);
		this.marketingGroupUsed.put("No".toUpperCase(), radioButton);

		label = this.newLabel("Packs own produce", 150);
		panel.add(label, 260, top);

		radioButton = new RadioButton("rad5", "Yes");
		panel.add(radioButton, 421, top);
		this.packsOwnProduce.put("Yes".toUpperCase(), radioButton);

		radioButton = new RadioButton("rad5", "No");
		panel.add(radioButton, 473, top);
		this.packsOwnProduce.put("No".toUpperCase(), radioButton);

		top = 25;

		label = this.newLabel("Market Group", 150);
		panel.add(label, 10, top);

		textBox = this.newTextBox("", 350);
		panel.add(textBox, 166, top);
		this.marketGroup = textBox;

		top = 45;

		label = this.newLabel("Brand", 150);
		panel.add(label, 10, top);

		textArea = new TextArea();
		panel.add(textArea, 166, top + 3);
		textArea.setSize("350px", "32px");
		this.brand = textArea;

		// TODO:htmlContact
		int width = 490;
		panel2 = new AbsolutePanel();
		panel2.setSize(width + "px", "524px");

		html = new HTML("<b style='color:red'>Contacts</b>");
		panel2.add(html, 10, 0);

		left = 500;
		html = new HTML("<img src='image/add.png' style='cursor:pointer;width:16px;height:16px'/>");
		panel2.add(html, width - 50, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				C.adminViewS.viewContactAdd(getMemberVo(), memberCallback);
			}
		});

		html = new HTML("<img src='image/save.png' style='cursor:pointer;width:16px;height:16px'/>");
		panel2.add(html, width - 20, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("Save this record?")) return;
				C.adminViewS.viewMemberSaveMail(getMemberVo(), memberCallback);
			}
		});

		this.panel.add(panel2, 10, 200);

		panel = new AbsolutePanel();
		panel.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
		panel.getElement().getStyle().setBorderWidth(2, Unit.PX);
		panel2.add(panel, 0, 20);
		panel.setSize(width - 4 + "px", "380px");

		this.tableContactHeader = new FlexTable();
		html = new HTML("");
		html.setWidth("30px");
		this.tableContactHeader.setWidget(0, 0, html);
		html = new HTML("<b><u>Contact Name</u></b>");
		html.setWidth("200px");
		this.tableContactHeader.setWidget(0, 1, html);
		html = new HTML("<b><u>Service(s)</u></b>");
		html.setWidth("170px");
		this.tableContactHeader.setWidget(0, 2, html);
		html = new HTML("");
		html.setWidth("30px");
		this.tableContactHeader.setWidget(0, 3, html);
		html = new HTML("");
		html.setWidth("30px");
		this.tableContactHeader.setWidget(0, 4, html);

		panel.add(this.tableContactHeader, 4, 0);

		this.tableContact = new FlexTable();
		AbsolutePanel tablePanel = new AbsolutePanel();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width - 12 + "px", "130px");
		tablePanel.add(this.tableContact, 0, 0);

		panel.add(tablePanel, 4, 14);

		html = new HTML("<span style='color:red'><b>Contact details for Tony Gugich</b></span>");
		panel.add(html, 4, 150);
		this.contactHTML = html;

		// TODO:htmlContactContact
		TabPanel tab;
		AbsolutePanel tabPanel;

		tab = new TabPanel();

		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width - 28 + "px", "175px");

		top = 0;
		left = 0;
		label = this.newLabel("First name", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("Tony", 120);
		tabPanel.add(textBox, left + 80, top);
		this.firstname = textBox;

		left = 240;
		label = this.newLabel("Surname", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("Gugich", 120);
		tabPanel.add(textBox, left + 80, top);
		this.surname = textBox;

		top = 22;
		left = 0;
		label = this.newLabel("BH Phone", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("0899418074", 120);
		tabPanel.add(textBox, left + 80, top);
		this.BHPhone = textBox;
		textBox.addBlurHandler(this.numberBlurHandler);

		left = 240;
		label = this.newLabel("AH Phone", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		tabPanel.add(textBox, left + 80, top);
		this.AHPhone = textBox;
		textBox.addBlurHandler(this.numberBlurHandler);

		top = 44;
		left = 0;
		label = this.newLabel("Fax", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("0899418078", 120);
		tabPanel.add(textBox, left + 80, top);
		this.fax = textBox;
		textBox.addBlurHandler(this.numberBlurHandler);

		left = 240;
		label = this.newLabel("Identifier", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		tabPanel.add(textBox, left + 80, top);
		this.identifier = textBox;

		top = 66;
		left = 0;
		label = this.newLabel("Mobile", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		tabPanel.add(textBox, left + 80, top);
		this.mobile = textBox;
		textBox.addBlurHandler(this.numberBlurHandler);

		top = 88;
		left = 0;
		label = this.newLabel("Email", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("", 320);
		tabPanel.add(textBox, left + 80, top);
		this.email = textBox;

		top = 120;
		left = 20;
		checkBox = new CheckBox("AMIA Activities FAX");
		tabPanel.add(checkBox, left, top);
		this.service.put("AMIA Activities FAX".toUpperCase(), checkBox);

		checkBox = new CheckBox("SMS for Workshops");
		tabPanel.add(checkBox, left + 200, top);
		this.service.put("SMS for Workshops".toUpperCase(), checkBox);

		top = 135;
		checkBox = new CheckBox("AMIA Activities EMAIL");
		tabPanel.add(checkBox, left, top);
		this.service.put("AMIA Activities EMAIL".toUpperCase(), checkBox);

		checkBox = new CheckBox("EMAIL for Workshops");
		tabPanel.add(checkBox, left + 200, top);
		this.service.put("EMAIL for Workshops".toUpperCase(), checkBox);

		top = 150;
		checkBox = new CheckBox("Mango Matters");
		tabPanel.add(checkBox, left, top);
		this.service.put("Mango Matters".toUpperCase(), checkBox);

		checkBox = new CheckBox("FAX for Workshops");
		tabPanel.add(checkBox, left + 200, top);
		this.service.put("FAX for Workshops".toUpperCase(), checkBox);

		tab.add(tabPanel, "Contact");

		// TODO:htmlContactAddress
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width - 28 + "px", "175px");

		top = 0;
		left = 0;
		label = this.newLabel("Business Address", 70);
		tabPanel.add(label, left, top);

		textArea = new TextArea();
		textArea.setSize(width - 120 + "px", "34px");
		tabPanel.add(textArea, left + 80, top);
		this.businessStreet = textArea;

		top = 44;
		left = 0;
		label = this.newLabel("City/Town", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		tabPanel.add(textBox, left + 80, top);
		this.businessCity = textBox;

		top = 66;
		left = 0;
		label = this.newLabel("State", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		tabPanel.add(textBox, left + 80, top);
		this.businessState = textBox;

		top = 88;
		left = 0;
		label = this.newLabel("Country", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		tabPanel.add(textBox, left + 80, top);
		this.businessCountry = textBox;

		top = 110;
		left = 0;
		label = this.newLabel("Post Code", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		tabPanel.add(textBox, left + 80, top);
		this.businessPostCode = textBox;

		tab.add(tabPanel, "Address");

		// TODO:htmlContactPostal
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width - 28 + "px", "175px");

		top = 0;
		left = 0;
		label = this.newLabel("Postal Address", 70);
		tabPanel.add(label, left, top);

		textArea = new TextArea();
		textArea.setSize(width - 120 + "px", "34px");
		tabPanel.add(textArea, left + 80, top);
		this.postalStreet = textArea;

		top = 44;
		left = 0;
		label = this.newLabel("City/Town", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		tabPanel.add(textBox, left + 80, top);
		this.postalCity = textBox;

		top = 66;
		left = 0;
		label = this.newLabel("State", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		tabPanel.add(textBox, left + 80, top);
		this.postalState = textBox;

		top = 88;
		left = 0;
		label = this.newLabel("Country", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		tabPanel.add(textBox, left + 80, top);
		this.postalCountry = textBox;

		top = 110;
		left = 0;
		label = this.newLabel("Post Code", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("", 120);
		tabPanel.add(textBox, left + 80, top);
		this.postalPostCode = textBox;

		tab.add(tabPanel, "Postal");

		// TODO:htmlContactMail
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width - 28 + "px", "175px");

		top = 0;
		left = 0;
		this.tableMail = new FlexTable();

		tablePanel = new AbsolutePanel();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width - 50 + "px", "90px");
		tablePanel.add(this.tableMail, 0, 0);

		tabPanel.add(tablePanel, 22, 0);

		top = 100;
		left = 0;
		label = this.newLabel("SAMPLE", 70);
		tabPanel.add(label, left, top);

		textArea = new TextArea();
		textArea.setSize(width - 120 + "px", "66px");
		textArea.setReadOnly(true);
		tabPanel.add(textArea, left + 80, top);
		this.sampleMail = textArea;

		tab.add(tabPanel, "Mail");

		// TODO:htmlContactEmailFax
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width - 28 + "px", "175px");

		top = 0;
		left = 0;
		this.tableEmailFax = new FlexTable();
		tablePanel = new AbsolutePanel();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width - 50 + "px", "90px");
		tablePanel.add(this.tableEmailFax, 0, 0);

		tabPanel.add(tablePanel, 22, 0);

		top = 100;
		left = 0;
		label = this.newLabel("SAMPLE", 70);
		tabPanel.add(label, left, top);

		textArea = new TextArea();
		textArea.setSize(width - 120 + "px", "66px");
		textArea.setReadOnly(true);
		tabPanel.add(textArea, left + 80, top);
		this.sampleEmailFax = textArea;
		tab.add(tabPanel, "Email/Fax");

		// TODO:htmlContactCallLog
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width - 28 + "px", "175px");
		tabPanel.add(new Label("AAAA"), 10, 10);
		tab.add(tabPanel, "Call Log");

		// TODO:htmlContactFailureLog
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width - 28 + "px", "175px");
		tabPanel.add(new Label("AAAA"), 10, 10);
		tab.add(tabPanel, "Failure Log");

		tab.selectTab(0);
		panel.add(tab, 4, 165);

		// TODO:htmlOrchard
		width = 490;
		panel2 = new AbsolutePanel();
		panel2.setSize(width + "px", "514px");

		html = new HTML("<b style='color:red'>Orchards</b>");
		panel2.add(html, 20, 0);

		left = 440;
		html = new HTML("<img src='image/add.png' style='cursor:pointer;width:16px;height:16px'/>");
		panel2.add(html, width - 50, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				C.adminViewS.viewOrchardAdd(getMemberVo(), memberCallback);
			}
		});

		html = new HTML("<img src='image/save.png' style='cursor:pointer;width:16px;height:16px'/>");
		panel2.add(html, width - 20, 0);
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				if (!Window.confirm("Save this record?")) return;
				C.adminViewS.viewMemberSaveMail(getMemberVo(), memberCallback);
			}
		});

		this.panel.add(panel2, width + 20, 200);

		panel = new AbsolutePanel();
		panel.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
		panel.getElement().getStyle().setBorderWidth(2, Unit.PX);
		panel2.add(panel, 0, 20);
		panel.setSize(width - 4 + "px", "380px");

		this.tableOrchardHeader = new FlexTable();
		html = new HTML("");
		html.setWidth("30px");
		this.tableOrchardHeader.setWidget(0, 0, html);
		html = new HTML("<b><u>Orchard Location</u></b>");
		html.setWidth("310px");
		this.tableOrchardHeader.setWidget(0, 1, html);
		html = new HTML("<b><u>Trees</u></b>");
		html.setWidth("60px");
		this.tableOrchardHeader.setWidget(0, 2, html);
		html = new HTML("");
		html.setWidth("30px");
		this.tableOrchardHeader.setWidget(0, 3, html);
		html = new HTML("");
		html.setWidth("30px");
		this.tableOrchardHeader.setWidget(0, 4, html);
		panel.add(this.tableOrchardHeader, 4, 0);

		this.tableOrchard = new FlexTable();
		tablePanel = new AbsolutePanel();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width - 12 + "px", "100px");
		tablePanel.add(this.tableOrchard, 0, 0);

		panel.add(tablePanel, 4, 14);

		html = new HTML("<span style='color:red'><b>Orchard details for Tony Gugich</b></span>");
		panel.add(html, 4, 115);
		this.orchardHTML = html;

		tab = new TabPanel();
		// TODO:htmlOrchardLocation
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width - 28 + "px", "100px");
		top = 5;
		left = 20;
		label = this.newLabel("Physical Address of Orchard", 70);
		tabPanel.add(label, left, top);

		textArea = new TextArea();
		textArea.setSize(width - 140 + "px", "32px");
		tabPanel.add(textArea, left + 80, top);
		this.physicalLocation = textArea;

		top = 50;
		label = this.newLabel("Post Code", 70);
		tabPanel.add(label, left, top);

		textBox = this.newTextBox("6701", 70);
		tabPanel.add(textBox, left + 80, top);
		this.postCode = textBox;

		label = this.newLabel("State", 70);
		tabPanel.add(label, left + 140, top);

		listBox = new ListBox();
		listBox.addItem("", "");
		listBox.addItem("QLD", "QLD");
		listBox.addItem("NT", "NT");
		listBox.addItem("WA", "WA");
		listBox.addItem("NSW", "NSW");
		listBox.addItem("VIC", "VIC");
		listBox.addItem("SA", "SA");
		listBox.addItem("ACT", "ACT");
		listBox.addItem("TAS", "TAS");
		tabPanel.add(listBox, left + 220, top);
		this.state = listBox;

		label = this.newLabel("Region", 70);
		tabPanel.add(label, left + 270, top);

		textBox = this.newTextBox("", 80);
		textBox.setReadOnly(true);
		tabPanel.add(textBox, left + 350, top);
		this.region = textBox;

		tab.add(tabPanel, "Orchard Locations");

		// TODO:htmlOrchardTree
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width - 28 + "px", "100px");

		this.tableTreeHeader = new FlexTable();
		html = new HTML("<b><u>Planted</u></b>");
		html.setWidth("70px");
		this.tableTreeHeader.setWidget(0, 0, html);
		html = new HTML("<b><u>Variety</u></b>");
		html.setWidth("160px");
		this.tableTreeHeader.setWidget(0, 1, html);
		html = new HTML("<b><u>DTR</u></b>");
		html.setWidth("32px");
		this.tableTreeHeader.setWidget(0, 2, html);
		html = new HTML("<b><u>BTR</u></b>");
		html.setWidth("32px");
		this.tableTreeHeader.setWidget(0, 3, html);
		html = new HTML("<b><u>Area</u></b>");
		html.setWidth("32px");
		this.tableTreeHeader.setWidget(0, 4, html);
		html = new HTML("<b><u>Type</u></b>");
		html.setWidth("62px");
		this.tableTreeHeader.setWidget(0, 5, html);
		html = new HTML("<b><u>Trees</u></b>");
		html.setWidth("40px");
		this.tableTreeHeader.setWidget(0, 6, html);
		html = new HTML("<img src='image/add.png' style='cursor:pointer;width:16px;height:16px'/>");
		html.setWidth("16px");
		html.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				C.adminViewS.viewTreeAdd(getMemberVo(), selectedOrchard.orchardId, memberCallback);
			}
		});
		this.tableTreeHeader.setWidget(0, 7, html);
		tabPanel.add(this.tableTreeHeader, 0, 0);

		this.tableTree = new FlexTable();
		tablePanel = new AbsolutePanel();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width - 28 + "px", "85px");
		tablePanel.add(this.tableTree, 0, 0);

		tabPanel.add(tablePanel, 0, 18);

		tab.add(tabPanel, "Tree Details");

		tab.selectTab(0);
		panel.add(tab, 4, 130);

		// TODO:htmlOrchardEmail
		tabPanel = new AbsolutePanel();
		tabPanel.setSize(width - 28 + "px", "100px");

		top = 0;
		left = 0;
		this.tableOrchardEmail = new FlexTable();
		tablePanel = new AbsolutePanel();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize(width - 50 + "px", "90px");
		tablePanel.add(this.tableOrchardEmail, 0, 0);

		tabPanel.add(tablePanel, 22, 0);

		tab.add(tabPanel, "Email");

		// TODO:htmlVariety
		this.tableVarietyHeader = new FlexTable();
		html = new HTML("<b><u>Variety totals for this producer</u></b>");
		html.setWidth("220px");
		this.tableVarietyHeader.setWidget(0, 0, html);
		html = new HTML("");
		html.setWidth("60px");
		this.tableVarietyHeader.setWidget(0, 1, html);
		panel.add(this.tableVarietyHeader, 4, 270);

		this.tableVariety = new FlexTable();
		tablePanel = new AbsolutePanel();
		tablePanel.getElement().getStyle().setOverflow(Overflow.AUTO);
		tablePanel.setSize("478px", "70px");
		tablePanel.add(this.tableVariety, 0, 0);
		panel.add(tablePanel, 4, 284);

		html = new HTML("<b style='color:red'>Total Trees for A & N Gugich is 900</b>");
		this.varietyHtml = html;
		panel.add(html, 20, 360);

		this.adminSearchView = AdminSearchView.get("");
		adminSearchView.searchHTML.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				C.adminViewS.viewMemberSearch(adminSearchView.adminSearchVo, memberCallback);
			}
		});

		adminSearchView.appendedSearchHTML.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				C.adminViewS.viewMemberSearch(adminSearchView.adminSearchVo, memberCallback);
				adminContactView.dialogBox.show();
			}
		});

		this.adminContactView = AdminContactView.get("");

		this.adminDbView = AdminDbView.get("");

		return this;
	}

	public AdminView view() {
		this.memberCallback.onSuccess(C._memberVo);
		return this;
	}

	public void setIsNumber(TextBox textBox) {
		try {
			if (!"".equals(textBox.getText().trim())) Integer.parseInt(textBox.getText().replaceAll(" ", ""));
			textBox.getElement().getStyle().clearBackgroundColor();
			textBox.getElement().getStyle().clearColor();
		} catch (Exception ex) {
			textBox.getElement().getStyle().setBackgroundColor("red");
			textBox.getElement().getStyle().setColor("white");
		}
	}

	public BlurHandler numberBlurHandler = new BlurHandler() {

		public void onBlur(BlurEvent event) {
			// TODO Auto-generated method stub
			TextBox textBox = (TextBox) event.getSource();
			setIsNumber(textBox);
		}
	};

	public AdminDbView adminDbView;
	public AdminSearchView adminSearchView;
	public AdminContactView adminContactView;
	//public MemberVo member;
	public ContactVo selectedContact;
	public HTML selectedContactHTML;
	public OrchardVo selectedOrchard;
	public HTML selectedOrchardHTML;

	public void setSampleMail() {
		if (selectedContact == null) {
			this.sampleMail.setText("");
			return;
		}
		this.sampleMail.setText(C._memberVo.getSampleMail(selectedContact, "\n"));
	}

	public void setSampleEmailFax() {
		if (selectedContact == null) {
			this.sampleEmailFax.setText("");
			return;
		}
		String str = null;
		for (int i = 0; i < C._memberVo.contactList.size(); i++) {
			ContactVo contact = C._memberVo.contactList.get(i);
			if (selectedContact.contactId.equals(contact.emailFaxContactId)) {
				if (str == null) str = "";
				else {
					if (i != C._memberVo.contactList.size() - 1) str += ", ";
					else str += " and ";
				}
				str += contact.firstname;
			}
		}
		this.sampleEmailFax.setText(str);
	}

	public void setContact(ContactVo contact) {
		contactId.setText(getString(contact.contactId));
		firstname.setText(contact.firstname);
		surname.setText(contact.surname);
		BHPhone.setText(contact.BHPhone);
		setIsNumber(BHPhone);
		AHPhone.setText(contact.AHPhone);
		setIsNumber(AHPhone);
		fax.setText(contact.fax);
		setIsNumber(fax);
		identifier.setText(contact.identifier);
		mobile.setText(contact.mobile);
		setIsNumber(mobile);
		email.setText(contact.email);
		String[] arr = getString(contact.service).split("&&");
		for (String key : service.keySet()) {
			service.get(key).setValue(false);
		}
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] == null || "".equals(arr[i])) continue;
			String str = arr[i].toUpperCase();
			CheckBox checkBox = (CheckBox) (service.get(str));
			if (checkBox != null) checkBox.setValue(true);
			else {
				System.out.println("missing:" + str);
			}
		}
		businessStreet.setText(contact.businessStreet);
		businessCity.setText(contact.businessCity);
		businessState.setText(contact.businessState);
		businessCountry.setText(contact.businessCountry);
		businessPostCode.setText(contact.businessPostCode);

		postalStreet.setText(contact.postalStreet);
		postalCity.setText(contact.postalCity);
		postalState.setText(contact.postalState);
		postalCountry.setText(contact.postalCountry);
		postalPostCode.setText(contact.postalPostCode);

		//String fullName = getString(contact.firstname) + " " + getString(contact.surname);
		contactHTML.setHTML("<span style='color:red'><b>" + contact.getCaption() + "</b></span>");

		HTML html;
		if (tableMail.getRowCount() > 0) {
			html = (HTML) tableMail.getWidget(0, 0);
			if (contact.mailMemberId != null && contact.mailMemberId.equals(C._memberVo.memberId)) {
				onLight(html);
			} else {
				offLight(html);
			}
		}

		for (int i = 0; i < tableMail.getRowCount(); i++) {
			html = (HTML) tableMail.getWidget(i, 1);
			html.getElement().getStyle().setVisibility(Visibility.HIDDEN);
		}
		for (int i = 0; i < tableEmailFax.getRowCount(); i++) {
			html = (HTML) tableEmailFax.getWidget(i, 1);
			html.getElement().getStyle().setVisibility(Visibility.HIDDEN);
		}
		for (int i = 0; i < C._memberVo.contactList.size(); i++) {
			ContactVo contact2 = C._memberVo.contactList.get(i);
			html = (HTML) tableMail.getWidget(i + 1, 0);
			if (contact.contactId != null && contact.contactId.equals(contact2.mailContactId)) {
				onLight(html);
			} else {
				offLight(html);
			}

			html = (HTML) tableMail.getWidget(i + 1, 1);
			if (contact2.mailContactId != null) {
				html.getElement().getStyle().setVisibility(Visibility.VISIBLE);
			}

			html = (HTML) tableMail.getWidget(0, 1);
			if (contact2.mailMemberId != null) {
				html.getElement().getStyle().setVisibility(Visibility.VISIBLE);
			}
			//
			html = (HTML) tableEmailFax.getWidget(i, 0);
			if (contact.contactId != null && contact.contactId.equals(contact2.emailFaxContactId)) {
				onLight(html);
			} else {
				offLight(html);
			}

			html = (HTML) tableEmailFax.getWidget(i, 1);
			if (contact2.emailFaxContactId != null) {
				html.getElement().getStyle().setVisibility(Visibility.VISIBLE);
			}
		}
		setSampleMail();
		setSampleEmailFax();
	}

	public AsyncCallback<MemberVo> memberCallback = new AsyncCallback<MemberVo>() {
		public void onSuccess(MemberVo member) {
			C._memberVo = member;
			//adminDbView.orchardListCallback.onSuccess(C._memberVo.orchardList);

			selectedContact = null;
			selectedOrchard = null;
			// TODO:Member
			if (C._memberVo == null) return;
			if (C._memberVo.current != null) current = C._memberVo.current;
			if (C._memberVo.memberIdList != null) memberIdList = C._memberVo.memberIdList;
			//if (C._memberVo.preAppended != null) AdminSearchView.get("").preAppended = C._memberVo.preAppended;

			if (C._memberVo.contactIdList != null) C._contactIdList = C._memberVo.contactIdList;
			if (C._memberVo.searchContactList != null) {
				C._searchContactList = C._memberVo.searchContactList;
				AdminContactView.get("").setContactEmail(C._searchContactList);
			}

			/*
			if (A.memberVo.adminDbVo != null) {
				//adminDbView.varietyList = member.varietyList;
				adminDbView.adminDbVoCallback.onSuccess(A.memberVo.adminDbVo);
			}
			*/
			final Map<String, String> varietyMap = C.getVarietyMap();

			currentHtml.setHTML("<b style='color:red'>" + current + " of " + memberIdList.size() + " [" + C._memberVo.getStatus() + "]</b>");
			currentTextBox.setText(current + "");

			memberId.setText(C._memberVo.memberId + "");
			businessName.setText(C._memberVo.businessName);
			abn.setText(C._memberVo.abn);
			String[] arr = getString(C._memberVo.businessType).split("&&");
			for (String key : businessType.keySet()) {
				businessType.get(key).setValue(false);
			}
			for (int i = 0; i < arr.length; i++) {
				if (arr[i] == null || "".equals(arr[i])) continue;
				String str = arr[i].toUpperCase();
				CheckBox checkBox = (CheckBox) (businessType.get(str));
				if (checkBox != null) checkBox.setValue(true);
				else {
					System.out.println("missing:" + str);
				}
			}
			other.setText(C._memberVo.other);

			for (String key : membershipType.keySet()) {
				membershipType.get(key).setValue(false);
				if (key.equals(C._memberVo.membershipType.toUpperCase())) membershipType.get(key).setValue(true);
			}
			for (String key : financialMember.keySet()) {
				financialMember.get(key).setValue(false);
				if (key.equals(C._memberVo.financialMember.toUpperCase())) financialMember.get(key).setValue(true);
			}
			for (String key : annualReport.keySet()) {
				annualReport.get(key).setValue(false);
				if (key.equals(C._memberVo.annualReport.toUpperCase())) annualReport.get(key).setValue(true);
			}

			for (String key : marketingGroupUsed.keySet()) {
				marketingGroupUsed.get(key).setValue(false);
				if (key.equals(C._memberVo.marketingGroupUsed.toUpperCase())) marketingGroupUsed.get(key).setValue(true);
			}
			for (String key : packsOwnProduce.keySet()) {
				packsOwnProduce.get(key).setValue(false);
				if (key.equals(C._memberVo.packsOwnProduce.toUpperCase())) packsOwnProduce.get(key).setValue(true);
			}
			marketGroup.setText(C._memberVo.marketGroup);
			brand.setText(C._memberVo.brand);

			// TODO:Contact
			tableRowRemove(tableContact);
			for (int i = tableMail.getRowCount() - 1; i >= 0; i--) {
				tableMail.removeRow(i);
			}
			for (int i = tableEmailFax.getRowCount() - 1; i >= 0; i--) {
				tableEmailFax.removeRow(i);
			}
			for (int i = tableOrchardEmail.getRowCount() - 1; i >= 0; i--) {
				tableOrchardEmail.removeRow(i);
			}
			contactHTML.setHTML("");

			HTML html;

			authorisedContact.clear();
			authorisedContact.addItem("", "");
			for (int i = 0; i < C._memberVo.contactList.size(); i++) {
				ContactVo contact = C._memberVo.contactList.get(i);
				// TODO:ContactDetail
				html = new HTML("<img src='image/detail.gif' style='cursor:pointer'/>");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {

					public void onClick(ClickEvent event) {
						HTML html = (HTML) event.getSource();
						selectedContactHTML = html;
						C._memberVo = getMemberVo();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						ContactVo contact = C._memberVo.contactList.get(index);
						selectedContact = contact;
						for (int i = tableContact.getRowCount() - 1; i >= 0; i--) {
							html = (HTML) tableContact.getWidget(i, 1);
							if (index == i) onLight(html);
							else offLight(html);
						}
						setContact(contact);
						/***********************
						 * setContact
						 * contactId.setText(getString(contact.contactId));
						 * firstname.setText(contact.firstname);
						 * surname.setText(contact.surname);
						 * BHPhone.setText(contact.BHPhone);
						 * setIsNumber(BHPhone);
						 * AHPhone.setText(contact.AHPhone);
						 * setIsNumber(AHPhone); fax.setText(contact.fax);
						 * setIsNumber(fax);
						 * identifier.setText(contact.identifier);
						 * mobile.setText(contact.mobile); setIsNumber(mobile);
						 * email.setText(contact.email); String[] arr =
						 * getString(contact.service).split("&&"); for (String
						 * key : service.keySet()) {
						 * service.get(key).setValue(false); } for (int i = 0; i
						 * < arr.length; i++) { if (arr[i] == null ||
						 * "".equals(arr[i])) continue; String str =
						 * arr[i].toUpperCase(); CheckBox checkBox = (CheckBox)
						 * (service.get(str)); if (checkBox != null)
						 * checkBox.setValue(true); else {
						 * System.out.println("missing:" + str); } }
						 * businessStreet.setText(contact.businessStreet);
						 * businessCity.setText(contact.businessCity);
						 * businessState.setText(contact.businessState);
						 * businessCountry.setText(contact.businessCountry);
						 * businessPostCode.setText(contact.businessPostCode);
						 * 
						 * postalStreet.setText(contact.postalStreet);
						 * postalCity.setText(contact.postalCity);
						 * postalState.setText(contact.postalState);
						 * postalCountry.setText(contact.postalCountry);
						 * postalPostCode.setText(contact.postalPostCode);
						 * 
						 * //String fullName = getString(contact.firstname) +
						 * " " + getString(contact.surname);
						 * contactHTML.setHTML("<span style='color:red'><b>" +
						 * contact.getCaption() + "</b></span>");
						 * 
						 * html = (HTML) tableMail.getWidget(0, 0); if
						 * (contact.mailMemberId != null &&
						 * contact.mailMemberId.equals(C._memberVo.memberId)) {
						 * onLight(html); } else { offLight(html); }
						 * 
						 * for (int i = 0; i < tableMail.getRowCount(); i++) {
						 * html = (HTML) tableMail.getWidget(i, 1);
						 * html.getElement
						 * ().getStyle().setVisibility(Visibility.HIDDEN); } for
						 * (int i = 0; i < tableEmailFax.getRowCount(); i++) {
						 * html = (HTML) tableEmailFax.getWidget(i, 1);
						 * html.getElement
						 * ().getStyle().setVisibility(Visibility.HIDDEN); } for
						 * (int i = 0; i < C._memberVo.contactList.size(); i++)
						 * { ContactVo contact2 =
						 * C._memberVo.contactList.get(i); html = (HTML)
						 * tableMail.getWidget(i + 1, 0); if (contact.contactId
						 * != null &&
						 * contact.contactId.equals(contact2.mailContactId)) {
						 * onLight(html); } else { offLight(html); }
						 * 
						 * html = (HTML) tableMail.getWidget(i + 1, 1); if
						 * (contact2.mailContactId != null) {
						 * html.getElement().getStyle
						 * ().setVisibility(Visibility.VISIBLE); }
						 * 
						 * html = (HTML) tableMail.getWidget(0, 1); if
						 * (contact2.mailMemberId != null) {
						 * html.getElement().getStyle
						 * ().setVisibility(Visibility.VISIBLE); } // html =
						 * (HTML) tableEmailFax.getWidget(i, 0); if
						 * (contact.contactId != null &&
						 * contact.contactId.equals(contact2.emailFaxContactId))
						 * { onLight(html); } else { offLight(html); }
						 * 
						 * html = (HTML) tableEmailFax.getWidget(i, 1); if
						 * (contact2.emailFaxContactId != null) {
						 * html.getElement
						 * ().getStyle().setVisibility(Visibility.VISIBLE); } }
						 * setSampleMail(); setSampleEmailFax();
						 *************/
					}
				});
				html.setWidth(tableContactHeader.getWidget(0, 0).getElement().getStyle().getWidth());
				tableContact.setWidget(i, 0, html);

				String fullName = contact.getCaption();//getString(contact.firstname) + " " + getString(contact.surname);
				authorisedContact.addItem(fullName, contact.contactId + "");
				if (contact.contactId.equals(C._memberVo.authorisedContact)) authorisedContact.setSelectedIndex(i + 1);
				html = new HTML(fullName);
				html.setWidth(tableContactHeader.getWidget(0, 1).getElement().getStyle().getWidth());
				tableContact.setWidget(i, 1, html);
				/*
				arr = ("" + contact.service).split("&&");
				String SMS = null;
				String EMAIL = null;
				String FAX = null;
				String mangoMatters = null;
				for (int j = 0; j < arr.length; j++) {
					if (arr[j].toUpperCase().indexOf("SMS") != -1) {
						SMS = "SMS";
					} else if (arr[j].toUpperCase().indexOf("EMAIL") != -1) {
						EMAIL = "EMAIL";
					} else if (arr[j].toUpperCase().indexOf("FAX") != -1) {
						EMAIL = "FAX";
					} else if (arr[j].toUpperCase().indexOf("Mango Matters".toUpperCase()) != -1) {
						mangoMatters = "Mango Matters";
					}

				}
				String service = "";
				if (SMS != null) service += SMS + ",";
				if (EMAIL != null) service += EMAIL + ",";
				if (FAX != null) service += FAX + ",";
				if (mangoMatters != null) service += mangoMatters + ",";
				if (!"".equals(service)) {
					service = service.substring(0, service.length() - 1);
				}
				*/
				html = new HTML(contact.getService());
				html.setWidth(tableContactHeader.getWidget(0, 2).getElement().getStyle().getWidth());
				tableContact.setWidget(i, 2, html);

				html = new HTML("<img src='image/remove.png' style='cursor:pointer'/>");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {

					public void onClick(ClickEvent event) {
						if (!Window.confirm("Remove this record?")) return;
						HTML html = (HTML) event.getSource();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						ContactVo contact = C._memberVo.contactList.get(index);
						C.adminViewS.viewContactRemove(getMemberVo(), contact.contactId + "", memberCallback);
					}
				});
				html.setWidth(tableContactHeader.getWidget(0, 3).getElement().getStyle().getWidth());
				tableContact.setWidget(i, 3, html);

				html = new HTML("<img src='image/active.png' style='cursor:pointer'/>");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {

					public void onClick(ClickEvent event) {
						if (!Window.confirm("Active this record?")) return;
						HTML html = (HTML) event.getSource();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						ContactVo contact = C._memberVo.contactList.get(index);
						C.adminViewS.viewContactActive(getMemberVo(), contact.contactId + "", memberCallback);
					}
				});
				html.setWidth(tableContactHeader.getWidget(0, 4).getElement().getStyle().getWidth());
				tableContact.setWidget(i, 4, html);

				// TODO:ContactMail
				if (i == 0) {
					html = new HTML("<b><u>" + C._memberVo.businessName + "</u></b>");
					html.setWidth("300px");
					tableMail.setWidget(0, 0, html);
					html = new HTML("<b style='color:red;'><u>ASSIGNED</u></b>");
					html.setWidth("70px");
					tableMail.setWidget(0, 1, html);
					html = new HTML("<img src='image/check.gif' style='cursor:pointer'/>");
					html.setWidth("25px");
					html.addClickHandler(new ClickHandler() {

						public void onClick(ClickEvent event) {
							HTML html = (HTML) event.getSource();
							selectedContact.mailMemberId = C._memberVo.memberId;
							C._memberVo = getMemberVo();
							ClickEvent.fireNativeEvent(Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false), selectedContactHTML);
						}
					});
					tableMail.setWidget(0, 2, html);
					html = new HTML("<img src='image/error.gif' style='cursor:pointer'/>");
					html.setWidth("25px");
					html.addClickHandler(new ClickHandler() {

						public void onClick(ClickEvent event) {
							HTML html = (HTML) event.getSource();
							selectedContact.mailMemberId = null;
							C._memberVo = getMemberVo();
							ClickEvent.fireNativeEvent(Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false), selectedContactHTML);
						}
					});
					tableMail.setWidget(0, 3, html);
				}
				html = new HTML(contact.getCaption());
				tableMail.setWidget(i + 1, 0, html);
				html = new HTML("<span style='color:red'>ASSIGNED<span>");
				tableMail.setWidget(i + 1, 1, html);
				html = new HTML("<img src='image/check.gif' style='cursor:pointer'/>");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {

					public void onClick(ClickEvent event) {
						HTML html = (HTML) event.getSource();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						ContactVo contact = C._memberVo.contactList.get(index);
						contact.mailContactId = selectedContact.contactId;
						C._memberVo = getMemberVo();
						ClickEvent.fireNativeEvent(Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false), selectedContactHTML);
					}
				});
				tableMail.setWidget(i + 1, 2, html);
				html = new HTML("<img src='image/error.gif' style='cursor:pointer'/>");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {

					public void onClick(ClickEvent event) {
						HTML html = (HTML) event.getSource();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						ContactVo contact = C._memberVo.contactList.get(index);
						contact.mailContactId = null;
						C._memberVo = getMemberVo();
						ClickEvent.fireNativeEvent(Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false), selectedContactHTML);
					}
				});
				tableMail.setWidget(i + 1, 3, html);
				// TODO:ContactEmailFax
				html = new HTML(contact.getCaption());
				html.setWidth("300px");
				tableEmailFax.setWidget(i, 0, html);
				html = new HTML("<span style='color:red'>ASSIGNED<span>");
				html.setWidth("70px");
				tableEmailFax.setWidget(i, 1, html);
				html = new HTML("<img src='image/check.gif' style='cursor:pointer'/>");
				html.setWidth("25px");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {

					public void onClick(ClickEvent event) {
						HTML html = (HTML) event.getSource();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						ContactVo contact = C._memberVo.contactList.get(index);
						contact.emailFaxContactId = selectedContact.contactId;
						C._memberVo = getMemberVo();
						ClickEvent.fireNativeEvent(Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false), selectedContactHTML);
					}
				});
				tableEmailFax.setWidget(i, 2, html);
				html = new HTML("<img src='image/error.gif' style='cursor:pointer'/>");
				html.setWidth("25px");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {

					public void onClick(ClickEvent event) {
						HTML html = (HTML) event.getSource();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						ContactVo contact = C._memberVo.contactList.get(index);
						contact.emailFaxContactId = null;
						C._memberVo = getMemberVo();
						ClickEvent.fireNativeEvent(Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false), selectedContactHTML);
					}
				});
				tableEmailFax.setWidget(i, 3, html);

				// TODO:OrchardEmail
				html = new HTML(contact.getCaption());
				html.setWidth("250px");
				tableOrchardEmail.setWidget(i, 0, html);
				html = new HTML("<span style='color:red'>ASSIGNED<span>");
				html.setWidth("70px");
				tableOrchardEmail.setWidget(i, 1, html);
				html = new HTML("<img src='image/check.gif' style='cursor:pointer'/>");
				html.setWidth("25px");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {

					public void onClick(ClickEvent event) {
						HTML html = (HTML) event.getSource();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						ContactVo contact = C._memberVo.contactList.get(index);
						//Window.alert("under construction");
						//contact.emailFaxContactId = selectedContact.contactId;
						////contact.emailOrchardId = selectedOrchard.orchardId;
						selectedOrchard.emailContactId = selectedOrchard.addStringList(selectedOrchard.emailContactId, contact.contactId);
						C._memberVo = getMemberVo();
						ClickEvent.fireNativeEvent(Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false), selectedOrchardHTML);
					}
				});
				tableOrchardEmail.setWidget(i, 2, html);
				html = new HTML("<img src='image/error.gif' style='cursor:pointer'/>");
				html.setWidth("25px");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {

					public void onClick(ClickEvent event) {
						HTML html = (HTML) event.getSource();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						ContactVo contact = C._memberVo.contactList.get(index);
						//Window.alert("under construction");
						//contact.emailFaxContactId = null;
						////contact.emailOrchardId = null;
						selectedOrchard.emailContactId = selectedOrchard.removeStringList(selectedOrchard.emailContactId, contact.contactId);
						C._memberVo = getMemberVo();
						ClickEvent.fireNativeEvent(Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false), selectedOrchardHTML);
					}
				});
				tableOrchardEmail.setWidget(i, 3, html);
			}

			if (tableContact.getRowCount() >= 1 && tableContact.getWidget(0, 0) != null) {
				html = (HTML) tableContact.getWidget(0, 0);
				ClickEvent.fireNativeEvent(Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false), html);
			} else {
				selectedContact = null;
				setContact(new ContactVo());
			}

			// TODO:Orchard
			tableRowRemove(tableOrchard);
			tableRowRemove(tableTree);
			tableRowRemove(tableVariety);
			physicalLocation.setText("");
			postCode.setText("");
			state.setSelectedIndex(0);
			orchardHTML.setHTML("");

			treeCountMap = new HashMap<String, Integer>();
			if (C._memberVo.orchardList.size() == 0) {
				for (int i = tableOrchardEmail.getRowCount() - 1; i >= 0; i--) {
					tableOrchardEmail.removeRow(i);
				}
			}
			for (int i = 0; i < C._memberVo.orchardList.size(); i++) {
				OrchardVo orchard = C._memberVo.orchardList.get(i);
				html = new HTML("<img src='image/detail.gif' style='cursor:pointer'/>");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {

					public void onClick(ClickEvent event) {
						HTML html = (HTML) event.getSource();
						TextBox textBox;
						ListBox listBox;
						selectedOrchardHTML = html;
						C._memberVo = getMemberVo();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						OrchardVo orchard = C._memberVo.orchardList.get(index);
						selectedOrchard = orchard;
						for (int i = tableOrchard.getRowCount() - 1; i >= 0; i--) {
							html = (HTML) tableOrchard.getWidget(i, 1);
							if (index == i) onLight(html);
							else offLight(html);
						}
						orchardId.setText(getString(orchard.orchardId));
						physicalLocation.setText(orchard.physicalLocation);
						postCode.setText(orchard.postCode);
						setListboxSelected(state, orchard.state);

						RegionVo regionVo = C.getRegionByPostCode(orchard.postCode);
						String str = "";
						if (regionVo != null) str = regionVo.regionName;
						region.setText(str);

						tableRowRemove(tableTree);

						for (int i = 0; i < orchard.treeList.size(); i++) {
							TreeVo tree = orchard.treeList.get(i);
							textBox = newTextBox(tree.yearPlanting, 60);
							tableTree.setWidget(i, 0, textBox);
							listBox = new ListBox();
							listBox.setWidth("160px");
							listBox.addItem("", "");
							for (String key : varietyMap.keySet()) {
								listBox.addItem(varietyMap.get(key), key);
							}
							setListboxSelected(listBox, tree.varietyId);
							tableTree.setWidget(i, 1, listBox);
							textBox = newTextBox(tree.DTR, 25);
							textBox.addBlurHandler(numberBlurHandler);
							setIsNumber(textBox);
							tableTree.setWidget(i, 2, textBox);
							textBox = newTextBox(tree.BTR, 25);
							textBox.addBlurHandler(numberBlurHandler);
							setIsNumber(textBox);
							tableTree.setWidget(i, 3, textBox);
							textBox = newTextBox(tree.area, 25);
							textBox.addBlurHandler(numberBlurHandler);
							setIsNumber(textBox);
							tableTree.setWidget(i, 4, textBox);
							listBox = new ListBox();
							listBox.setWidth("60px");
							listBox.addItem("", "");
							listBox.addItem("Acres", "Acres");
							listBox.addItem("Hectares", "Hectares");
							setListboxSelected(listBox, tree.areaType);
							tableTree.setWidget(i, 5, listBox);
							textBox = newTextBox(tree.tree + "", 33);
							textBox.addBlurHandler(numberBlurHandler);
							setIsNumber(textBox);
							tableTree.setWidget(i, 6, textBox);
							html = new HTML("<img src='image/remove.png' style='cursor:pointer'/>");
							html.getElement().setAttribute("index", i + "");
							html.addClickHandler(new ClickHandler() {

								public void onClick(ClickEvent event) {
									if (!Window.confirm("Remove this record?")) return;
									HTML html = (HTML) event.getSource();
									int index = Integer.parseInt(html.getElement().getAttribute("index"));
									TreeVo tree = selectedOrchard.treeList.get(index);
									C.adminViewS.viewTreeRemove(getMemberVo(), tree.treeId, memberCallback);
								}
							});
							tableTree.setWidget(i, 7, html);
						}
						//String location = getFirstLine(orchard.physicalLocation);
						orchardHTML.setHTML("<span style='color:red'><b>" + orchard.getLocation() + "</b></span>");

						for (int i = 0; i < tableOrchardEmail.getRowCount(); i++) {
							html = (HTML) tableOrchardEmail.getWidget(i, 1);
							html.getElement().getStyle().setVisibility(Visibility.HIDDEN);
						}
						for (int i = 0; i < C._memberVo.contactList.size(); i++) {
							ContactVo contact2 = C._memberVo.contactList.get(i);
							html = (HTML) tableOrchardEmail.getWidget(i, 0);
							if (orchard.orchardId != null && orchard.inStringList(orchard.emailContactId, contact2.contactId)) {
								onLight(html);
							} else {
								offLight(html);
							}
							/*
							html = (HTML) tableOrchardEmail.getWidget(i, 1);
							if (contact2.emailOrchardId != null) {
								html.getElement().getStyle().setVisibility(Visibility.VISIBLE);
							}*/
						}
					}
				});
				html.setWidth(tableOrchardHeader.getWidget(0, 0).getElement().getStyle().getWidth());
				tableOrchard.setWidget(i, 0, html);
				//String location = getFirstLine(orchard.physicalLocation);
				html = new HTML(orchard.getLocation());
				html.setWidth(tableOrchardHeader.getWidget(0, 1).getElement().getStyle().getWidth());
				tableOrchard.setWidget(i, 1, html);
				int treeLocationCount = 0;
				for (int j = 0; j < orchard.treeList.size(); j++) {
					TreeVo tree = orchard.treeList.get(j);
					treeLocationCount += tree.tree;
					if (tree.varietyId != null) {
						String varietyName = varietyMap.get(tree.varietyId + "");
						Integer treeCount = treeCountMap.get(varietyName);
						if (treeCount == null) treeCount = 0;
						treeCountMap.put(varietyName, treeCount + tree.tree);
					}
				}
				html = new HTML(treeLocationCount + "");
				html.setWidth(tableOrchardHeader.getWidget(0, 2).getElement().getStyle().getWidth());
				tableOrchard.setWidget(i, 2, html);

				html = new HTML("<img src='image/remove.png' style='cursor:pointer'/>");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {

					public void onClick(ClickEvent event) {
						if (!Window.confirm("Remove this record?")) return;
						HTML html = (HTML) event.getSource();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						OrchardVo orchard = C._memberVo.orchardList.get(index);
						C.adminViewS.viewOrchardRemove(getMemberVo(), orchard.orchardId + "", memberCallback);

					}
				});
				html.setWidth(tableOrchardHeader.getWidget(0, 3).getElement().getStyle().getWidth());
				tableOrchard.setWidget(i, 3, html);

				html = new HTML("<img src='image/active.png' style='cursor:pointer'/>");
				html.getElement().setAttribute("index", i + "");
				html.addClickHandler(new ClickHandler() {

					public void onClick(ClickEvent event) {
						if (!Window.confirm("Active this record?")) return;
						HTML html = (HTML) event.getSource();
						int index = Integer.parseInt(html.getElement().getAttribute("index"));
						OrchardVo orchard = C._memberVo.orchardList.get(index);
						C.adminViewS.viewOrchardActive(getMemberVo(), orchard.orchardId + "", memberCallback);

					}
				});
				html.setWidth(tableOrchardHeader.getWidget(0, 4).getElement().getStyle().getWidth());
				tableOrchard.setWidget(i, 4, html);
			}
			if (tableOrchard.getRowCount() >= 1 && tableOrchard.getWidget(0, 0) != null) {
				html = (HTML) tableOrchard.getWidget(0, 0);
				ClickEvent.fireNativeEvent(Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false), html);
			}
			// TODO:Variety
			int i = 0;
			totalTree = 0;
			for (String key : treeCountMap.keySet()) {
				Integer treeCount = treeCountMap.get(key);
				html = new HTML(key);
				html.setWidth(tableVarietyHeader.getWidget(0, 0).getElement().getStyle().getWidth());
				tableVariety.setWidget(i, 0, html);
				html = new HTML(treeCount + "");
				html.setWidth(tableVarietyHeader.getWidget(0, 1).getElement().getStyle().getWidth());
				tableVariety.setWidget(i, 1, html);
				totalTree += treeCount;
				i++;
			}
			varietyHtml.setHTML("<b style='color:red'>Total Trees for " + C._memberVo.businessName + " is " + totalTree + "</b>");
			if (C._memberVo.flowerList != null) adminDbView.flowerListCallback.onSuccess(C._memberVo.flowerList);
		}

		public void onFailure(Throwable caught) {

		}
	};

	public MemberVo getMemberVo() {
		//public Integer memberId;
		C._memberVo.businessName = this.businessName.getText();
		C._memberVo.abn = this.abn.getText();
		C._memberVo.businessType = this.getCheckBoxString(this.businessType);
		C._memberVo.other = this.other.getText();
		C._memberVo.membershipType = this.getRadioButtonString(this.membershipType);
		C._memberVo.financialMember = this.getRadioButtonString(this.financialMember);
		C._memberVo.annualReport = this.getRadioButtonString(this.annualReport);
		C._memberVo.authorisedContact = this.getListboxInteger(this.authorisedContact);
		C._memberVo.marketingGroupUsed = this.getRadioButtonString(this.marketingGroupUsed);
		C._memberVo.packsOwnProduce = this.getRadioButtonString(this.packsOwnProduce);
		C._memberVo.marketGroup = this.marketGroup.getText();
		C._memberVo.brand = this.brand.getText();

		if (this.selectedContact != null) {

			//		public Integer contactId;
			//		public Integer memberId;
			this.selectedContact.firstname = this.firstname.getText();
			this.selectedContact.surname = this.surname.getText();
			this.selectedContact.BHPhone = this.BHPhone.getText();
			this.selectedContact.AHPhone = this.AHPhone.getText();
			this.selectedContact.fax = this.fax.getText();
			this.selectedContact.identifier = this.identifier.getText();
			this.selectedContact.mobile = this.mobile.getText();
			this.selectedContact.email = this.email.getText();
			this.selectedContact.service = this.getCheckBoxString(this.service);
			this.selectedContact.businessStreet = this.businessStreet.getText();
			this.selectedContact.businessCity = this.businessCity.getText();
			this.selectedContact.businessState = this.businessState.getText();
			this.selectedContact.businessCountry = this.businessCountry.getText();
			this.selectedContact.businessPostCode = this.businessPostCode.getText();
			this.selectedContact.postalStreet = this.postalStreet.getText();
			this.selectedContact.postalCity = this.postalCity.getText();
			this.selectedContact.postalState = this.postalState.getText();
			this.selectedContact.postalCountry = this.postalCountry.getText();
			this.selectedContact.postalPostCode = this.postalPostCode.getText();

			//		public Integer mailMemberId;
			//		public Integer mailContactId;
			//		public Integer emailFaxContactId;
		}
		if (this.selectedOrchard != null) {
			//this.selectedOrchard.orchardId;
			//this.selectedOrchard.memberId;
			this.selectedOrchard.physicalLocation = this.physicalLocation.getText();
			this.selectedOrchard.postCode = this.postCode.getText();
			this.selectedOrchard.state = this.state.getValue(this.state.getSelectedIndex());

			for (int i = 0; i < this.selectedOrchard.treeList.size(); i++) {
				TreeVo tree = this.selectedOrchard.treeList.get(i);
				TextBox textBox = (TextBox) tableTree.getWidget(i, 0);
				tree.yearPlanting = textBox.getText();
				ListBox listBox = (ListBox) tableTree.getWidget(i, 1);
				tree.varietyId = getListboxInteger(listBox);
				textBox = (TextBox) tableTree.getWidget(i, 2);
				tree.DTR = textBox.getText();
				textBox = (TextBox) tableTree.getWidget(i, 3);
				tree.BTR = textBox.getText();
				textBox = (TextBox) tableTree.getWidget(i, 4);
				tree.area = textBox.getText();
				listBox = (ListBox) tableTree.getWidget(i, 5);
				tree.areaType = listBox.getValue(listBox.getSelectedIndex());
				textBox = (TextBox) tableTree.getWidget(i, 6);
				Integer num = 0;
				try {
					num = (Integer) Integer.parseInt(textBox.getText());
				} catch (Exception ex) {
				}
				tree.tree = num;

			}
		}
		return C._memberVo;
	}

	public void gotoMember(String memberId) {
		try {
			int num = -1;
			for (int i = 0; i < memberIdList.size(); i++) {
				if (memberId.equals(memberIdList.get(i))) num = i + 1;
			}
			if (num == -1) {
				Window.alert("Record not in list");
				return;
			}
			current = num;
			C.adminViewS.viewMember(memberIdList.get(current - 1), memberCallback);
			AdminContactView.get("").dialogBox.hide();
			AdminDbView.get("").dialogBox.hide();
		} catch (Exception ex) {

		}
	}
}
